home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13897 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: castle.nando.net!news
  2. From: Caius Martius <caius@nando.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why does this work?
  5. Date: Wed, 27 Mar 1996 17:27:33 -0800
  6. Organization: Carolantic Realty, Inc.
  7. Message-ID: <3159EB05.4E1C@nando.net>
  8. References: <DoxvnA.L0C@mail.auburn.edu>
  9. NNTP-Posting-Host: vyger1215.nando.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I; 16bit)
  14.  
  15. John M. Greer wrote:
  16. > This is probably a horribly simple question, but I was going through a
  17. > few books, brushing up on my iostreams, when I saw this tidbit in Jamsa's
  18. > Multimedia Trilogy (The CD-ROM by Kris Jamsa)
  19. > #include <iostream.h>
  20. > #include <ctype.h>
  21. > void main(void)
  22. >  {
  23. >    char letter;
  24. >    while (! cin.eof())
  25. >      {
  26. >        letter = cin.get();
  27. >        letter = toupper(letter);
  28. >        cout << letter;
  29. >      }
  30. >  }
  31. > Why does this work!?!?  It seems to reserve storage for only one
  32. > character in letter, but outputs a whole line at a time.  Feel free to
  33. > flame my stupidity, but please satisfy my curiosity (I'm really not this
  34. > clueless, I promise!!)
  35. > John Greer
  36.  
  37. To further explain, when you run the program and type a word, the word is 
  38. not stored in letter.  Instead the word is stored in the stream buffer 
  39. and is read one character at a time by get().
  40.